<?php
// Redirects to a new page.
function redirect_to($where) {
    if ($where == "back") {
        header("Location: " . $_SERVER["HTTP_REFERER"]);
        exit(0);
    }
    
	header("Location: $where");
	exit(0);
}

// Check if session is started, if not,
// starts a new one.
function check_session_or_start_new() {
	if (!isset($_SESSION)) session_start();
}         

// Checks if a variable is defined in $_SESSION
function is_in_session($variable_name) {
	return ( (!isset($_SESSION[$variable_name])) OR (empty($_SESSION[$variable_name])) );
}

// 
// Add a flash message to the session
//
function set_flash($message) {
    $_SESSION["flash"] = $message;
}

//
// Gets the flash message
//
function get_flash($clean_after_return = false) {

		if ( !isset($_SESSION["flash"]) ) {

			return false; 

		}

    $message = $_SESSION["flash"];
    
    if ($clean_after_return)
        $_SESSION["flash"] = null;

    return $message;

}
?>
